/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bsc.war.form;

import bsc.ejb.entity.Person;
import bsc.ejb.metadata.Colorimetry;
import bsc.ejb.metadata.Framework;
import bsc.ejb.metadata.SMTP;
import bsc.war.delegate.DelegateBSC;
import bsc.war.factory.Factory;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.lang.math.NumberUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

/**
 *
 * @author luisZavaleta
 */
public class Acordeon extends AbstractController {

    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();

        try {

            HttpSession session = request.getSession();
            Colorimetry col;
            DelegateBSC delegate = (DelegateBSC) Factory.getBean("DelegateBSC");

            Framework framework;
            if (NumberUtils.isDigits(request.getParameter("frameworkId"))) {
                Long frameworkId = Long.valueOf(request.getParameter("frameworkId"));
                framework = delegate.findFramework(frameworkId);
                session.setAttribute("frameworkId", frameworkId);
            } else {
                //Redirigir a la página principal
                throw new Exception("No existe el framework");
            }

            String frameId = request.getParameter("frame");


            //Upload Persons
            List<Person> persons = delegate.findPerson();
            //remove system users
            persons.remove(delegate.findPerson(1L));
            persons.remove(delegate.findPerson(2L));
            mav.addObject("persons", persons);


            mav.addObject("colorimetries", delegate.findColorimetry(framework, Boolean.TRUE));
            mav.addObject("langs", delegate.findLang(framework, Boolean.TRUE));
            mav.addObject("notetypes", delegate.findNoteType(framework, Boolean.TRUE));
            mav.addObject("units", delegate.findUnit(framework, Boolean.TRUE));
            mav.addObject("mapDrawings", delegate.findMapDrawing(framework, Boolean.TRUE));
            mav.addObject("comparations", delegate.findComparation(framework, Boolean.TRUE));
            mav.addObject("smtp", delegate.findSMTP(framework));


            SMTP sm = new SMTP();
            /*
            mav.addObject("notLangs", delegate.findLang(framework, Boolean.FALSE));
            mav.addObject("notNoteTypes", delegate.findNoteType(framework, Boolean.FALSE));
            mav.addObject("notUnits", delegate.findUnit(framework, Boolean.FALSE));
            mav.addObject("notMapDrawings", delegate.findMapDrawing(framework, Boolean.FALSE));
            mav.addObject("notComparators", delegate.findComparation(framework, Boolean.FALSE));
             */
            session.setAttribute("framework", framework);
        } catch (Exception e) {
        }


        return mav;
    }
}
